# Contributor: David Demelier <markand@malikania.fr>
# Maintainer: David Demelier <markand@malikania.fr>
pkgname=lmms
pkgver=1.2.2
pkgrel=4
pkgdesc="Cross-platform music production software"
url="https://lmms.io/"
# carla architectures
arch="armv7 aarch64 riscv64 x86 x86_64"
license="GPL-2.0-only"
makedepends="
	alsa-lib-dev
	carla-dev
	cmake
	extra-cmake-modules
	fftw-dev
	fluidsynth-dev
	jack-dev
	libsamplerate-dev
	libsndfile-dev
	patchelf
	pulseaudio-dev
	qt5-qtbase-dev
	qt5-qttools-dev
	qt5-qtx11extras-dev
	samurai
	sdl12-compat-dev
	xcb-util-dev
	xcb-util-keysyms-dev
	"
depends="
	$pkgname-plugins-ladspa
	"
subpackages="
	$pkgname-dev
	$pkgname-doc
	$pkgname-bash-completion
	$pkgname-plugins-ladspa
	"
source="https://github.com/LMMS/lmms/releases/download/v$pkgver/lmms_$pkgver.tar.xz
	kf5widgets-new.patch
	system-carla.patch
	"
options="!check" # No tests
builddir="$srcdir/$pkgname"
ldpath="/usr/lib/lmms"

build() {
	if [ "$CBUILD" != "$CHOST" ]; then
		CMAKE_CROSSOPTS="-DCMAKE_SYSTEM_NAME=Linux -DCMAKE_HOST_SYSTEM_NAME=Linux"
	fi
	CFLAGS="$CFLAGS -O2 -DNDEBUG -flto=auto -Wno-deprecated-declarations" \
	CXXFLAGS="$CXXFLAGS -O2 -DNDEBUG -flto=auto -Wno-deprecated-declarations" \
	cmake -B build -G Ninja -Wno-dev \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_INSTALL_LIBDIR=lib \
		-DBUILD_SHARED_LIBS=True \
		-DCMAKE_BUILD_TYPE=None \
		-DFORCE_VERSION="$pkgver-alpine-r$pkgrel" \
		-DWANT_QT5=ON \
		-DWANT_PULSEAUDIO=ON \
		-DWANT_WEAKJACK=OFF \
		$CMAKE_CROSSOPTS
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build

	install -Dm644 doc/bash-completion/lmms \
		-t "$pkgdir"/usr/share/bash-completion/completions/

	# these need to find the plugins via NEEDED but usr/lib/carla is not in rpath
	patchelf --set-rpath /usr/lib/carla \
		"$pkgdir"/usr/lib/lmms/libcarlapatchbay.so \
		"$pkgdir"/usr/lib/lmms/libcarlarack.so
}

ladspa() {
	depends=""
	amove usr/lib/lmms/ladspa
}

sha512sums="
df74d9e938f1c3807e9941b11db4ccfe9450e23b723c82774de15b7666ac39f1bfdd8519231e28849f994628190ecc92fa05d55bbc0b50a4421f2d183e729028  lmms_1.2.2.tar.xz
77b3ef74245e903064c7eeb2fd6e0e14ff46acc96b72fa506106903413bd012365601659e8ff4f74b3aa09cbfbc4a7d56259e5661026a6b9d894c96dc997da95  kf5widgets-new.patch
f7ae784af9f9d5fb00882554799f1d5f4cd4526a23ff8f9fa69616d26b5413f39437c5454f7a5d867d6aa1de95555d91202684294495f8e7f79f3b99ba09d7c8  system-carla.patch
"
